package logic

import (
	"context"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassAddLogic {
	return &ClassAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品添加分类
func (l *ClassAddLogic) ClassAdd(in *productrpc.ClassAddRequest) (*productrpc.ClassAddResponse, error) {
	// todo: add your logic here and delete this line
	class := mysql.Class{
		UserId: in.UserId,
		Name:   in.Name,
	}
	mysql.DB.Debug().Create(&class)

	return &productrpc.ClassAddResponse{
		Id: int64(class.ID),
	}, nil
}
